package com.niiwoo.civet.trade.dao.mapper;

import com.niiwoo.civet.trade.dao.entity.ProjectBorrowerPlanNew;
import com.niiwoo.civet.trade.dto.ProjectBorrowerPlanNewDTO;
import com.niiwoo.civet.trade.dto.common.CurrMonthRefundPlanDTO;
import com.niiwoo.civet.trade.dto.request.ProjectBorrowerPlanRequestDTO;
import com.niiwoo.civet.trade.dto.response.CustomSysBorrowerInfoDTO;
import com.niiwoo.civet.trade.dto.response.myloan.LoanGoingResponseDTO;
import com.niiwoo.civet.trade.dto.response.myloan.LoanPlanDateResponseDTO;
import com.niiwoo.civet.trade.dto.response.myloan.LoanPlanMonthResponseDTO;
import org.apache.ibatis.annotations.Param;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

public interface ProjectBorrowerPlanNewMapperExt extends ProjectBorrowerPlanNewMapper {


	/**
	 * 扫描需还款用户
	 * @return
	 */
	List<String> listRepayUserIds(String date);

	/**
	 * 根据标的查询所有还款计划
	 * @param projectId
	 * @return
	 */
	List<ProjectBorrowerPlanNew> selectByProjectId(@Param("projectId") Long projectId);

	/**
	 * 查询下一期待还计划
	 * @param projectId
	 * @return
	 */
	ProjectBorrowerPlanNew selectNextNotRefunPeriod(@Param("projectId") Long projectId);

	/**
	 *
	 * @param projectId
	 * @return
	 */
	List<ProjectBorrowerPlanNew> selectByProjectIdAndPeriods(@Param("projectId") Long projectId,@Param("list") List<Integer> periods);


	/**
	 * 根据标的,时间统计逾期期数
	 * @param projectId
	 * @return
	 */
	Integer countOverDuePeriodByProjectIdRefundDate(@Param("projectId") Long projectId, @Param("refundDate")Date refundDate);
	/**
	 * 根据标的ID与期数查询还款计划
	 * 
	 * @param projectId
	 * @param period
	 * @return
	 */
	ProjectBorrowerPlanNew selectByProjectAndPeriod(@Param("projectId") Long projectId, @Param("period") Integer period);
	
	/**
	 * 根据项目ID查询还款计划
	 * 
	 * 详情的金额转化成横表，方便业务使用
	 * 
	 * @param projectId
	 * @return
	 */
	List<ProjectBorrowerPlanNewDTO> selectByProjectIdForAmount(@Param("projectId") Long projectId);

	Integer selectByProjectIdNum(@Param("projectId") Long projectId);

	List<ProjectBorrowerPlanNewDTO> selectByProjectIdForAmountPage(@Param("params") ProjectBorrowerPlanRequestDTO requestDTO);
	
	/**
	 * 获取指定期的还款计划详情
	 * 
	 * @param projectId
	 * @param period
	 * @return
	 */
	ProjectBorrowerPlanNewDTO selectByProjectIdAndPeroidForAmount(@Param("projectId") Long projectId, @Param("period") Integer period);

	/**
	 * 根据项目id和当期期数查询还款计划
	 * @param projectId
	 * @param period
	 * @return
	 */

	List<ProjectBorrowerPlanNew> selectBorrowerPlanByProjectIdAndCurrentPeriodBefore(@Param("projectId") Long projectId, @Param("period") Integer period);

	/**
	 * 查询标的逾期期数
	 * 
	 * @param userId
	 * @param projectId
	 * @return
	 */
	Integer countOverdueNums(@Param("userId") String userId,@Param("projectId") Long projectId);
	
	/**
	 * 
	 * 查询当前的还款计划
	 * 
	 * @param userId
	 * @param today
	 * @return
	 */
	List<ProjectBorrowerPlanNew> selectByUserIdForToday(@Param("userId") String userId, @Param("today") String today);

	/**
	 * 按日期统计还款计划
	 * 
	 * @param userId
	 * 				用户ID
	 * @return
	 */
	Integer selectLoanPlanDateCount(@Param("userId") String userId);
	
	/**
	 * 按日期查询还款计划
	 * 
	 * @param userId
	 * 				用户ID
	 * @param start
     * @param end
     * @return
	 */
	List<LoanPlanDateResponseDTO> selectLoanPlanDateList(@Param("userId") String userId, @Param("start") Integer start, @Param("end") Integer end);
	
	/**
	 * 按日期统计还款计划
	 * 
	 * @param userId
	 * 				用户ID
	 * @return
	 */
	Integer selectLoanPlanMonthCount(@Param("userId") String userId);
	
	/**
	 * 按日期查询还款计划
	 * 
	 * @param userId
	 * 				用户ID
	 * @param start
     * @param end
     * @return
	 */
	List<LoanPlanMonthResponseDTO> selectLoanPlanMonthList(@Param("userId") String userId, @Param("start") Integer start, @Param("end") Integer end);

	/**
	 * 找出需要还款的回款计划列表
	 * @param projectId
	 * @param compareDate
	 * @return
	 */
    List<ProjectBorrowerPlanNew> selectNeedRefundList(@Param("projectId") Long projectId, @Param("compareDate") Date compareDate);

	/**
	 * 获取标的历史逾期最高天数
	 * 
	 * @param projectId
	 * @param userId
	 * @return
	 */
	Integer selectMaxOverdueDayForHistory(@Param("projectId") Long projectId, @Param("userId") String userId);
	/**
     * 查询愈期超过一定天数的标的-已逾期还款
     * 
     * @param userId 用户ID
     * @param exceedDays 愈期天数
     * @return
     */
	Integer selectOverdueExceedConditionRepayment(@Param("userId") String userId, @Param("exceedDays") Integer exceedDays);
	
	List<CurrMonthRefundPlanDTO> selectShouldRefundProjectsWithPreData(@Param("userId") String userId);
	
	Integer selectMyloanGoingCount(@Param("userId") String userId);
	
	List<LoanGoingResponseDTO> selectMyloanGoings(@Param("userId") String userId, @Param("start") Integer start, @Param("end") Integer end);
	
	LoanGoingResponseDTO selectMyloanGoingsByProjectIdAndPeriod(@Param("projectId") Long projectId, @Param("period") Integer period);
	
	/**
	 * 查询用户待还期数列表
	 * 
	 * @param userId
	 * @return
	 */
	List<Integer> queryShouldRepayPeriods(@Param("userId") String userId);
	
	/**
	 * 查询标的已还款最大期数
	 * 
	 * @param projectId
	 * @return
	 */
	Integer queryLastFinishPeriod(@Param("projectId") Long projectId);

	/**
	 * 查询指定期数已还款个数
	 * @param projectId
	 * @param periods
	 * @return
	 */
	Integer countReceivedNumberByProjectIdAndPeriods(@Param("projectId") Long projectId,@Param("list") List<Integer> periods);

	/**
	 * 查询用户所有已还金额
	 * @param userId
	 * @return
	 */
	BigDecimal selectRefundCapitalByUser(@Param("userId") String userId);

	/**
	 * 查询用户所有逾期还款金额
	 * @param userId
	 * @return
	 */
	BigDecimal selectOverdueAmountByUser(@Param("userId") String userId);

	/**
	 * 查询用户所有正常还款金额
	 * @param userId
	 * @return
	 */
	BigDecimal selectRepaymentAmountByUser(@Param("userId") String userId);

	/**
	 * 按用户统计逾期总期数
	 * 
	 * @param userId
	 * @param currentDate
	 * @return
	 */
	Integer countByUserIdForOverduePeriod(@Param("userId") String userId, @Param("currentDate") Date currentDate);

	Date selectLastRefundDayByProjectId(@Param("projectId") Long projectId);

	List<Long> selectNotRefundAndAmountZeroList(@Param("projectId") Long projectId);

	List<Long> selectAllNotRefundAndAmountZeroList();
	/**
	 * 客户系统查询当期还款信息
	 * @param projectId
	 * @return
	 */
	CustomSysBorrowerInfoDTO queryCurrentPeriodRefundInfoByProjectId(@Param("projectId") Long projectId);
	
	/**
	 * 客户系统查询还款信息列表
	 * @param projectId
	 * @return
	 */
	List<CustomSysBorrowerInfoDTO> queryRefundListInfoByProjectId(@Param("projectId") Long projectId);
}